package net.sansi.v3correctserver.entity.color;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import net.sansi.v3correctserver.entity.HashEquals;
import net.sansi.v3correctserver.entity.V3Cloneable;
import net.sansi.v3correctserver.util.RGBUtil;

import java.util.Objects;

/**
 * Created by Fang
 * create time : 2024/10/31
 * IDE : IntelliJ IDEA
 * <p>
 * V3 色度
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class CIEChroma extends HashEquals implements V3Cloneable<CIEChroma> {
    // CIE1931 的 xyY, 这里的 Y 用 bright 表示
    private double x;
    private double y;
    private double bright;

    /**
     * z 坐标（蓝色）
     *
     * @return z
     */
    public double getZ() {
        return 1.0000 - x - y;
    }

    /**
     * 转换为V3Color
     *
     * @return V3Color
     */
    public PhotoColor toPhotoColor() {
        double[] rgb = RGBUtil.rgbToCIE(this.x, this.y, this.bright);
        return new PhotoColor(
                rgb[0],
                rgb[1],
                rgb[2]
        );
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    /**
     * 重构hashCode
     * 是的 x，y，bright 一样的对象，hashCode 也一样， equals判断一致
     *
     * @return hashCode
     */
    @Override
    public int hashCode() {
        return Objects.hash(x, y, bright);
    }

    @Override
    public CIEChroma clone(boolean isDeep) {
        return new CIEChroma(x, y, bright);
    }


}
